<?php
    foreach($categories as $row){
        $categories_aux[] = $row;
    }
?>
<h1>Administrar Categorías</h1>
<ul>
    <?php foreach($categories_aux as $category1){ ?>
        <?php if($category1->getParentId()==null){ ?>
            <li>
                <?php echo $category1->getName(); ?>
                [
                <a href="<?php echo url_for("@categories_new?parent_id=".$category1->getId()); ?>">+</a>
                /
                <a href="<?php echo url_for("@categories_edit?category_id=".$category1->getId()); ?>">E</a>
                /
                <a href="<?php echo url_for("@categories_disable?category_id=".$category1->getId()); ?>" onclick="return delete_confirm();">-</a>
                ]
            </li>
            <ul>
                <?php foreach($categories_aux as $category2){ ?>
                    <?php if($category2->getParentId()==$category1->getId()){ ?>
                        <li>
                            <?php echo $category2->getName(); ?>
                            [
                            <a href="<?php echo url_for("@categories_new?parent_id=".$category2->getId()); ?>">+</a>
                            /
                            <a href="<?php echo url_for("@categories_edit?category_id=".$category2->getId()); ?>">E</a>
                            /
                            <a href="<?php echo url_for("@categories_disable?category_id=".$category2->getId()); ?>" onclick="return delete_confirm();">-</a>
                            ]
                        </li>
                        <ul>
                            <?php foreach($categories_aux as $category3){ ?>
                                <?php if($category2->getId()==$category3->getParentId()){ ?>
                                <li>
                                    <?php echo $category3->getName(); ?>
                                    [
                                    <a href="<?php echo url_for("@categories_new?parent_id=".$category3->getId()); ?>">+</a>
                                    /
                                    <a href="<?php echo url_for("@categories_edit?category_id=".$category3->getId()); ?>">E</a>
                                    /
                                    <a href="<?php echo url_for("@categories_disable?category_id=".$category3->getId()); ?>" onclick="return delete_confirm();">-</a>
                                    ]
                                </li>
                                <?php } ?>
                            <?php } ?>
                        </ul>
                    <?php } ?>
                <?php } ?>
            </ul>
        <?php } ?>
    <?php } ?>
</ul>